import { http } from "@/utils/http";

type UploadResult = {
  id: number;
  originalName: string;
  file_path: string;
  file_domain: string;
  size: number;
  file_type: number;
  md5: string;
  path: string;
  type: string;
  ext: string;
};

// 图片上传API
export const uploadApi = {
  // 上传图片
  uploadImage: (file: File): Promise<UploadResult> => {
    const formData = new FormData();
    formData.append('image', file);
    
    return http.request<UploadResult>('post', '/upload-image', { 
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  // 上传文件
  uploadFile: (file: File): Promise<UploadResult> => {
    const formData = new FormData();
    formData.append('file', file);
    
    return http.request<UploadResult>('post', '/upload-file', { 
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  }
}; 